Ext.define('app.system.coding.grid', {
	extend : "Ext.grid.Panel",
	frame : false,
	border : false,
	requires : [ 'app.system.model.coding', 'app.system.coding.form' ],
	initComponent : function() {
		var me = this;
		var me = this;
		var columns = me.createColumns();
		var store = me.createStore();
		var dockitems = new Array();
		var toolarray = me.createTool();
		if (toolarray.length > 0) {
			dockitems.push(widget.toolbar(toolarray));
		}
		dockitems.push(widget.paging(store));
		Ext.apply(me, {
			store : store,
			columns : columns,
			singleExpand : me.singleExpand || true,
			dockedItems : dockitems
		});
		store.load();
		me.callParent(arguments);
	},
	createTool : function() {
		var me = this;
		var array = new Array();
		utils.pushbtnarray(array, {
			text : '编辑',
			handler : function() {
				var rec = utils.single(me);
				if (rec != null) {
					Ext.create('app.system.coding.form', {
						parentTarget : me,
						codingId : rec.get('codingId')
					}).show();
				} else {
					Ext.Msg.alert('提示', '请选择记录');
				}
			}
		});
		utils.pushbtnarray(array, {
			text : '启用',
			handler : function() {
				var rec = utils.single(me);
				if (rec != null) {
					var param = {
						codingId : rec.get('codingId')
					};
					evt.confirm(me, '是否启用?', systemUrl
							+ '/boyon/coding/start', param, function() {
						me.store.reload();
					});
				} else {
					Ext.Msg.alert('提示', '请选择记录');
				}
			}
		});
		return array;
	},
	createStore : function() {
		return widget.ds({
			clazz : 'app.system.model.coding',
			url : systemUrl + '/boyon/coding/query'
		});
	},
	createColumns : function() {
		var array = new Array();
		array.push(widget.column({
			dataIndex : 'codingId',
			width : 80,
			text : '编码ID'
		}));
		array.push(widget.column({
			dataIndex : 'codingName',
			width : 180,
			text : '编码名称'
		}));
		array.push(widget.column({
			dataIndex : 'codingKey',
			width : 120,
			text : '关键字'
		}));
		array.push(widget.column({
			dataIndex : 'preffixType',
			width : 120,
			text : '前缀类型',
			renderer : function(v) {
				return utils.getValueField('t' + 10, v);
			}
		}));
		array.push(widget.column({
			dataIndex : 'codingType',
			width : 120,
			text : '编码类型',
			renderer : function(v) {
				return utils.getValueField('t' + 1, v);
			}
		}));
		array.push(widget.column({
			dataIndex : 'preffix',
			width : 120,
			text : '前缀'
		}));
		array.push(widget.column({
			dataIndex : 'style',
			width : 120,
			text : '格式'
		}));
		array.push(widget.column({
			dataIndex : 'status',
			width : 120,
			text : '状态',
			renderer : function(v) {
				return utils.getValueField('t' + 7, v);
			}
		}));
		return array;
	},
	reloadStore : function() {
		var me = this;
		me.store.reload();
	}
});